﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Skywave.DataStructure
{
    public class KeyAllowingDuplicates<keyType> : IComparable<KeyAllowingDuplicates<keyType>>
    {
        public KeyAllowingDuplicates()
        {
        }
        public KeyAllowingDuplicates(keyType key)
        {
            _Key = key;
        }
        public KeyAllowingDuplicates(keyType key, bool asc)
        {
            _Key = key;
            _Ascending = asc;
        }

        /// <summary>
        /// Key stored
        /// </summary>
        public keyType Key
        {
            get
            { return _Key; }
            set { _Key = value; }
        }
        private keyType _Key;

        /// <summary>
        /// True(default): Ascending , False=Descending
        /// </summary>
        public bool Ascending
        {
            get
            { return _Ascending; }
            set { _Ascending = value; }
        }
        private bool _Ascending = true;


        #region IComparable<KeyAllowingDuplicates<keyType>> Members

        public int CompareTo(KeyAllowingDuplicates<keyType> other)
        {
            int r;
            if (_Ascending)
                r = ((IComparable<keyType>)_Key).CompareTo(other._Key);
            else
                r = -((IComparable<keyType>)_Key).CompareTo(other._Key);
            if (r == 0) r = -1;
            return r;
        }

        #endregion
    }
}
